package com.cqc.selectorphoto;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

import me.nereo.multi_image_selector.MultiImageSelector;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn1;
    private Context context;
    private static final int REQUEST_IMAGE = 0;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        findViews();
        initViews();
    }

    private void initViews() {
        btn1.setOnClickListener(this);
    }

    private void findViews() {
        btn1 = (Button) findViewById(R.id.btn1);
        tv = (TextView) findViewById(R.id.tv);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                //详细调用API
//                MultiImageSelector.create(context)
//                        .showCamera(true) // 是否显示相机. 默认为显示
//                        .count(9) // 最大选择图片数量, 默认为9. 只有在选择模式为多选时有效
//                        //.single() // 单选模式
//                        .multi() // 多选模式, 默认模式;
//                        //.origin(ArrayList < String >) // 默认已选择图片. 只有在选择模式为多选时有效
//                        .start(MainActivity.this, REQUEST_IMAGE);
                //简单调用
                MultiImageSelector.create().start(MainActivity.this,REQUEST_IMAGE);
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE) {
            if (resultCode == RESULT_OK) {
                // 获取返回的图片列表(存放的是图片路径)
                List<String> path = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                // 处理你自己的逻辑 ....
                Log.d("tag", "" + path);
                tv.setText(""+path);
            }
        }
    }
}
